from sqlalchemy import Column, String, create_engine, Integer, Float, DATE
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
class User(Base):
    __tablename__ = 'daily_prices'
    # id = Column(String(20), primary_key=True)
    # name = Column(String(20))
    id = Column(Integer,primary_key=True,autoincrement=True)
    # name = Column(String(200))
    # money = Column(Float)
    datetime = Column(DATE)
    price = Column(Float)

engine = create_engine('mysql+mysqlconnector://root:123456@localhost:3306/test')

DBSession = sessionmaker(bind=engine)

def update(datatime, daily_btc_price):
    session = DBSession()
    new_user = User(datetime=datatime, price=daily_btc_price)
    session.add(new_user)
    session.commit()
    session.close()

'''
def query(datatime):
    session = DBSession()
    user = session.query(price).filter(User.id=='1').one()
    print ('type:', type(user))
    print ('name:', user.datetime)
    print(user.price)
    session.close()
'''